﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="text/javascript" th:src="@{/home/js/public.js}"></script>
</head>
<style> 
.special{color:#C0C0C0;} 
</style>
	<body>
		<div class="navigation-t">
	   	  <div class="navigation-tl">当前位置：<a href="#" onclick="changeMain('home')">主页</a> > 权限管理</div>
	   	  <div class="navigation-tr">
	   	  	<ul>
	   	  		<li onclick="changeMain('operation/user/1')"><span>用户管理</span></li>
	   	  		<li onclick="changeMain('operation/authority/1')" class="active"><span>权限管理</span></li>
	   	  		<li onclick="changeMain('password')"><span>修改密码</span></li>
	   	  	</ul>
	   	  </div>
	    </div>
	    <div class="project">
	    	<div class="project-padding"> 
	       	  <div class="table-tool project-t">
	       	  	 <div class="table-tool-btn">
	       	  	 	<div class="tool-btn"    id="authority-add"><span class="add-icon"></span><a>新增</a></div>
	       	  	 	<div class="tool-btn"    id="authority-edit"   ><span class="edit-icon"></span><a>编辑</a></div>
	       	  	 	<div class="tool-btn"    id="authority-del"  ><span class="del-icon"></span><a>删除</a></div>
	       	  	 	<div class="tool-btn"    id="authorization"><span class="authorization-icon"></span><a>权限设置</a></div>
	          	 </div>
	          	 <div class="table-tool">
		          	<div class="table-tool-ser">
		          	 	<div class="tool-ser"><input type="text" class="form-control" placeholder="输入查询条件"  id="search1"/></div>
		          	 	<div class="tool-btn"  onclick="js_method()"><span class="ser-icon"></span><a>搜索</a></div>
		          	</div>
	             </div>
	          </div>
	          <!--内容开始-->
	          <div class="table-head">
	          	<table width="100%" align="center" cellpadding="0" cellspacing="0" border="0">
	          		<thead>
		          		<tr>
		          			<td width="4%"><input type="checkbox" /></td>
		          			<td width="6%">序号</td>
		          			<td width="45%">用户角色</td>
		          			<td width="45%">备注</td>
		          		</tr>
	          		</thead>
	          		<tbody>
		          			<tr  th:each="row,iterStat : ${rows}">
		          			  <td><input type="checkbox" name="select_item"    th:disabled="${row.roleName=='系统管理员'||row.roleName=='审计管理员'}? 'true' : 'false'" /></td>
		          			  <td><font  th:class="${row.roleName=='系统管理员'||row.roleName=='审计管理员'}? 'special' : ''"    th:text="${iterStat.count}"></font></td>
							  <td name="id" th:text="${row.id}" style="display: none">id</td>
						      <td name="roleName"><font th:class="${row.roleName=='系统管理员'||row.roleName=='审计管理员'}? 'special' : ''" th:text="${row.roleName}"></font></td>
		          			  <td><font th:class="${row.roleName=='系统管理员'||row.roleName=='审计管理员'}? 'special' : ''"  th:text="${row.roleRemark}"></font></td>
		          		   </tr>
	          		</tbody>
	          	</table>
	          </div>
	          <!--内容结束-->
	          <!--分页开始-->
	       <div class="multimedia-c">
				<ul class="pagination" id="pagination">
				</ul>
				<input type="hidden" id="PageCount" runat="server" /> <input
					type="hidden" id="PageSize" runat="server" value="5" /> <input
					type="hidden" id="countindex" runat="server" value="10" />
				<!--设置最多显示的页码数 可以手动设置 默认为4-->
				<input type="hidden" id="visiblePages" runat="server" value="4" />
			</div>
	          <!--分页结束-->
	       </div>
	    </div>

	</body>
	<script src="home/js/HomePage.js" type="text/javascript"></script>

<script th:inline="javascript">  

/*<![CDATA[*/  
	$(function() {
		$('#authority-add').on('click', function(e) {
			e.preventDefault();
			var diag = new $.Zebra_Dialog({
				source : {
					'iframe' : {
						'id':'authority',
						'src' : 'authority-add.html?timestamp='+new Date().getTime(),
						'height':300
					}
				},
				width : 600,
				title : '新增',
			    buttons:  [
			               {caption: '保存', callback: function() { 
			            	   
			            	   
			            		var validate=document.getElementById("authority").contentWindow.getData();
			            		  if(!validate){
			            			 return false;
			            		 }
			            	   var data= document.getElementById("authority").contentWindow.getDataJson("roleForm");
			           		   var obj = JSON.stringify(data);
			       		     	AjaxWebTableInfo("/Role/saveOrUpdate",data);
			                  }}
	                        ]
			});
		});
		
		

		$('#authorization').on('click', function(e) {
			e.preventDefault();
			if($('input[name="select_item"]:checked').length==1){
				var checkBoxs= $('input[name="select_item"]:checked').parent();
				var id=checkBoxs.parent().parent().find("[name='id']").text();
				var roleName=checkBoxs.parent().parent().find("[name='roleName']").text();
			   var  html="authorization.html"
				if(roleName=="系统管理员"){
					html="authorizationXT.html";
				}else if(roleName=="审计管理员"){
					html="authorizationSJ.html";
					
				}
				var diag = new $.Zebra_Dialog({
					source : {
						'iframe' : {
							'id':'authorization_1',
						    'src':'edit/'+html+'?timestamp='+new Date().getTime()+'&roleId='+id,
				            'height':500
						}
					},
					 width:1000,
			        title:'权限设置',
				    buttons:  [
				               {caption: '保存', callback: function() { 
				            	   var data= document.getElementById("authorization_1").contentWindow.getDataJson("perForm");
				            	  
				           		  var obj = JSON.stringify(data);
				       		      AjaxWebTableInfo("/Permission/saveOrUpdate",data);
				       		 	 // window.location.href="/index"
				                  }}
		                        ]
				});
				
				
				
			}else{
				 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一行!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
			}
		
		});
		
		$('#authority-del').on('click', function(e) {
			e.preventDefault();
			var checkBoxs= $('input[name="select_item"]:checked').parent();
			var ids=checkBoxs.parent().parent().find("[name='id']");
		    var  id="";
  		   for (var i=0;i<ids.length;i++)
			{
  				if(i<ids.length-1){
  					id += $(ids[i]).text()+",";
  				}else{
  					id += $(ids[i]).text();
  				}
			} 
			if(id!=""){ $.ajax({
			     type: "post",
			     dataType: "json",
			     url:"/Role/dele" ,
			     data:{id:id},
			     success: function (data, status) {
			    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">删除成功!</div></div>', {
				            'title':'提示',
				            'buttons':['确定']
				         });
			  	    $("#frameReft").load("/operation/authority/1?timestamp="+new Date().getTime());
			     },
			     error: function (data) {
			    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">删除失败!</div></div>', {
				            'title':'提示',
				            'buttons':['确定']
				         });
			     }
			 });}else{
				
				 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一行!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
			} 
  		
  		   
		 });
		$('#authority-edit').on('click', function(e) {
			e.preventDefault();
			if($('input[name="select_item"]:checked').length==1){
				var checkBoxs= $('input[name="select_item"]:checked').parent();
				var id=checkBoxs.parent().parent().find("[name='id']").text();
				var diag = new $.Zebra_Dialog({
					source : {
						'iframe' : {
							'id':'authority',
							'src' : 'edit/authority-edit.html?id='+id,
							'height':300
						}
					},
					width : 600,
					title : '编辑',
				    buttons:  [
				               {caption: '保存', callback: function() { 
				            	   
				            		var validate=document.getElementById("authority").contentWindow.getData();
				            		  if(!validate){
				            			 return false;
				            		 }
				            	   var data= document.getElementById("authority").contentWindow.getDataJson("roleForm");
				           		   var obj = JSON.stringify(data);
				       		       AjaxWebTableInfo("/Role/saveOrUpdate",data);
				                  }}
		                        ]
				});
				
				
				
			}else{
				 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一行!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
			}
		
		});
	
	})
	function AjaxWebTableInfo(url , obj){
		 $.ajax({
		     type: "post",
		     dataType: "json",
		     url: url,
		     data:obj,
		     success: function (data, status) {
		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">保存成功!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
		  	    $("#frameReft").load("/operation/authority/1?timestamp="+new Date().getTime());
		     },
		     error: function (data) {
		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">保存失败!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
		     }
		 });	
	}
	/*]]>*/  
	
</script>	    
 <script th:inline="javascript">  
/*<![CDATA[*/  
    var total ="[[${total}]]";
    var pageNo ="[[${pageNo}]]"; 
    var  search=[[${search}]]
    $("#search1").val(search);
    $("#PageCount").val(total);
    loadpage(pageNo,"operation/authority/",$("#search1").val());
	function js_method(){
	 var search= $("#search1").val();
	 $("#frameReft").load("/operation/authority/1?timestamp="+new Date().getTime(),{'search': search});
	}
	
/*]]>*/  
</script>
</html>
